﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    <link href="@Url.Content("~/lib/summernote/0.8.15/summernote.min.css")" rel="stylesheet" type="text/css">
    <script src='@Url.Content("~/lib/summernote/0.8.15/summernote.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/summernote/0.8.15/lang/summernote-zh-CN.min.js")' type="text/javascript"></script>

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/css/imgup.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/js/imgup.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"))
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label ">标题<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="bnTitle" col="BnTitle" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">副标题1</label>
            <div class="col-sm-8">
                <input id="bnSubtitle" col="BnSubtitle" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">副标题2</label>
            <div class="col-sm-8">
                <input id="bnT1" col="BnT1" type="text" class="form-control" />
            </div>
        </div>
        @*<div class="form-group">
            <label class="col-sm-2 control-label ">副标题3</label>
            <div class="col-sm-8">
                <input id="bnT2" col="BnT2" type="text" class="form-control" />
            </div>
        </div>*@
        <div class="form-group">
            <label class="col-sm-2 control-label ">
                <span>Banner缩略图</span><br />
                <span>(宽高比 1.5：1)</span>
            </label>
            <div class="col-sm-8">
                <div id="bnImage" class="img-box">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">链接地址</label>
            <div class="col-sm-8">
                <input id="bnUrl" col="BnUrl" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">备注</label>
            <div class="col-sm-8">

                <textarea id="bnRemark" col="BnRemark" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">主图位置</label>
            <div class="col-sm-8">

                <select id="bnContent" col="BnContent" class="form-control">
                    <option>左</option>
                    <option>右</option>
                </select>
            </div>
        </div>
        @*<div class="form-group">
            <label class="col-sm-2 control-label ">BnDate</label>
            <div class="col-sm-8">
                <input id="bnDate" col="BnDate" type="text" class="form-control" />
            </div>
        </div>
        *@
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        $("#bnImage").imageUpload({ uploadImage: 'uploadThumbImage', limit: 1, context: ctx });
        getForm();

        $('#form').validate({
            rules: {
                bnTitle: { required: true }
            }
        });
    });

    function getForm() {
        console.log(id)
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Banner/GetFormJson")' + '?id=' + id,
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {

                        $("#form").setWebControls(obj.Result);

                        $("#bnImage").imageUpload("setImageUrl", obj.Result.BnImage);

                    }
                }
            });
        }
        else {

            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Banner/GetFormJson")',
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        var defaultData = {};

                        defaultData.NewsSort = obj.Result;
                        $("#form").setWebControls(defaultData);
                    }
                }
            });
        }
    }

    function saveForm(index) {

        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls({ Id: id });

            postData.BnImage = $("#bnImage").imageUpload("getImageUrl");

            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Banner/SaveFormJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }

    function uploadNewsImage(file, editor, welEditable) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    $("#newsContent").summernote('insertImage', '@GlobalContext.SystemConfig.ApiSite' + obj.Result, '/');
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }

    function uploadThumbImage(file, callback) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    if (callback) {
                        callback('@GlobalContext.SystemConfig.ApiSite' + obj.Result);
                    }
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }
</script>

